//
//  OperateHistoryCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/27.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "OperateHistoryCell.h"

@interface OperateHistoryCell ()

@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *valueLabel;
@property (nonatomic, strong) UILabel *noteLabel;

@end

@implementation OperateHistoryCell

+ (OperateHistoryCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"OperateHistoryCell";
    OperateHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[OperateHistoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(20), ScreenX375(0), ScreenX375(53), ScreenX375(60))];
    self.timeLabel.textColor = FONTCOLOR_BLACK;
    self.timeLabel.font = Kfont(15);
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    self.timeLabel.numberOfLines = 0;
    [self addSubview:self.timeLabel];
    
    self.valueLabel = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - ScreenX375(100)) / 2, ScreenX375(20), ScreenX375(100), ScreenX375(20))];
    self.valueLabel.textColor = FONTCOLOR_BLACK;
    self.valueLabel.font = Kfont(18);
    self.valueLabel.text = @"+100";
    self.valueLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.valueLabel];
    
    self.noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(104), ScreenX375(20), ScreenX375(80), ScreenX375(20))];
    self.noteLabel.textColor = FONTCOLOR_BLACK;
    self.noteLabel.font = Kfont(14);
    self.noteLabel.text = @"提现成功";
    self.noteLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.noteLabel];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(24), ScreenX375(60) - 0.5, SCREEN_WIDTH - ScreenX375(48), 0.5)];
    line.backgroundColor = LineColor;
    [self addSubview:line];
}

- (void)setOperateModel:(OperateModel *)operateModel {
    _operateModel = operateModel;
    
    self.valueLabel.text = [NSString stringWithFormat:@"%@",operateModel.price];
    
    NSArray * arrWeek=[NSArray arrayWithObjects:@"周日",@"周一",@"周二",@"周三",@"周四",@"周五",@"周六", nil];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate* date = [dateFormatter dateFromString:[HttpManager TimeStamp:operateModel.createTime]];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSCalendarUnitWeekday;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:date];
    
    NSInteger week = [dateComponent weekday];
    
    NSString *string = [NSString stringWithFormat:@"%@\n%@",[arrWeek objectAtIndex:week-1],[[HttpManager TimeStamp:operateModel.createTime] substringWithRange:NSMakeRange(5, 5)]];
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:string];
    [attributedStr addAttribute:NSFontAttributeName value:Kfont(14) range:NSMakeRange(2, string.length - 2)];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:REXADECIMALCOLOR(@"#ababab") range:NSMakeRange(2, string.length - 2)];
    self.timeLabel.attributedText = attributedStr;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@implementation OperateModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}


@end
